import statService from '@/api/stat/stat'
import { getDateByType } from '@/libs/tools'
let data = new class {
  // 下载文件工具

  constructor() {
    this.xAxisData = [];
    this.data=[];

    // this.createData()
  }
  setConfig(param){
    // 为整个类设置个性化参数
    return this
  }

  async getData(dataType) {
    let param = {dataType: dataType,endHour:getDateByType('h')+1}
    let {success,data}=await statService.queryTimeCount(param)
    // console.log(data);
    return {success,data}
  }

  async countIn(){
    let res=await this.getData(0)
    if (res.success) {
      let count=[];
      let me = this;
      me.xAxisData=[]
      res.data.forEach(item => {
        me.xAxisData.push(parseInt(item.curHour));
        count.push(parseInt(item.count));
      })
      return count;
    }
  }
  async countOut(){
    let res=await this.getData(1)
    if (res.success) {
      let count=[];
      let me = this;
      res.data.forEach((item,i) => {
        count.push(parseInt(item.count));
      })
      return count;
    }
  }
  async createData(){
    let countIn = await this.countIn();
    let countOut = await this.countOut();
    this.data.push(countIn, countOut);
    return {
      "xAxisData": this.xAxisData,
      "data":this.data
    };
}
}

export {
data
}
